// DlgEditNotes.cpp : implementation file
//

#include "stdafx.h"
#include "Celsus.h"
#include "DlgEditNotes.h"


// CDlgEditNotes dialog

IMPLEMENT_DYNAMIC(CDlgEditNotes, CDialog)

CDlgEditNotes::CDlgEditNotes(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgEditNotes::IDD, pParent)
{
	m_nItemID = -1;
}

CDlgEditNotes::~CDlgEditNotes()
{
}

void CDlgEditNotes::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EXPLORER_REQUEST_NOTES, m_ctrlRequestNotes);
	DDX_Control(pDX, IDC_EXPLORER_STAFF_INFORMATION, m_ctrlStaffInformation);	
}


BEGIN_MESSAGE_MAP(CDlgEditNotes, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_COLOR2, &CDlgEditNotes::OnBnClickedButtonColor)
	ON_BN_CLICKED(IDC_BUTTON_FONT2, &CDlgEditNotes::OnBnClickedButtonFont)
	ON_BN_CLICKED(IDC_BUTTON_BOLD2, &CDlgEditNotes::OnBnClickedButtonBold2)
	ON_BN_CLICKED(IDC_BUTTON_ITALIC2, &CDlgEditNotes::OnBnClickedButtonItalic2)
END_MESSAGE_MAP()


// CDlgEditNotes message handlers

BOOL CDlgEditNotes::OnInitDialog()
{
	ASSERT( m_nItemID > -1 );
	CDialog::OnInitDialog();

	// get notes
	// set title
	CString szText;
	szText.Format( _T("Notes for Request: %.8ld"), m_nItemID );
	SetWindowText( szText );

	// get request
	REQUEST_SET Request;
	if( !appConfig.m_SQL.GetRequestSet( &Request, m_nItemID ))
	{
		AfxMessageBox( _T("ERROR getting request.") );
		EndDialog( IDCANCEL );
		return TRUE;
	}

	// show info
	m_ctrlRequestNotes.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
	appConfig.SetHTML( &m_ctrlRequestNotes, Request.m_notes );
	appConfig.SetEdit( &m_ctrlRequestNotes );

	// show info
	m_ctrlStaffInformation.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
	appConfig.SetHTML( &m_ctrlStaffInformation, Request.m_information );
	appConfig.SetEdit( &m_ctrlStaffInformation );

	// update data
	UpdateData( FALSE );

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgEditNotes::OnOK()
{
	// update data
	UpdateData();

	// get request
	REQUEST_SET Request;
	if( !appConfig.m_SQL.GetRequestSet( &Request, m_nItemID ))
	{
		AfxMessageBox( _T("ERROR getting request.") );
		EndDialog( IDCANCEL );
		return;
	}

	// get notes
	appConfig.GetHTMLBody( &m_ctrlRequestNotes, Request.m_notes );
	// get information
	appConfig.GetHTMLBody( &m_ctrlStaffInformation, Request.m_information );

	// update request
	appConfig.m_SQL.SetRequestSet( &Request );

	CDialog::OnOK();
}

void CDlgEditNotes::OnBnClickedButtonColor()
{
	CColorDialog dlg;
	if( dlg.DoModal() == IDOK )
	{
		COLORREF cColor = dlg.GetColor();
		// set them both at the same time since they both can be highlighted
		appConfig.SetColor( &m_ctrlRequestNotes, cColor );
		appConfig.SetColor( &m_ctrlStaffInformation, cColor );
	}
}

void CDlgEditNotes::OnBnClickedButtonFont()
{
}

void CDlgEditNotes::OnBnClickedButtonBold2()
{
	// set them both at the same time since they both can be highlighted
	appConfig.SetBold( &m_ctrlRequestNotes );
	appConfig.SetBold( &m_ctrlStaffInformation );
}

void CDlgEditNotes::OnBnClickedButtonItalic2()
{
	// set them both at the same time since they both can be highlighted
	appConfig.SetItalic( &m_ctrlRequestNotes );
	appConfig.SetItalic( &m_ctrlStaffInformation );
}
